/**
 * 详情对话框
 */
var CompanyInfoDlg = {
    data: {
        logo: "",
        name: "",
        fullName: "",
        industryId: "",
        staffSize: "",
        companyProfile: "",
        businessLicense: "",
        address: "",
        longitude: "",
        latitude: "",
        verifyStatus: "",
        refuseReason: "",
        status: "",
        createBy: "",
        createTime: "",
        updateBy: "",
        updateTime: "",
        remark: ""
    }
};

layui.use(['form', 'admin', 'ax','carousel'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/company/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('companyForm', result.data);
    $('#demo1').attr('src',result.data.logo);//获取图片
    var imgs=result.data.album.split(',');
    for (var i=0;i<imgs.length;i++){
        var a='<div><img style="width: 600px;height: 280px;" src="'+imgs[i]+'"></div>';
        console.log("a===========",a);
        $('#banner').append(a);
    }

    var carousel = layui.carousel //轮播
    //执行一个轮播实例
    var ins =carousel.render({
        elem: '#test1'
        ,arrow: 'always',
        interval:2000,
        arrow:'none'
    });

    !function(){
        var infoWindow, map, level = 11,
            center = {lng: result.data.longitude, lat: result.data.latitude},
            features = [{"icon":"cir","color":"red","name":"天安门","desc":"未命名标注描述","lnglat":{"Q":result.data.latitude,"R":result.data.longitude,"lng":result.data.longitude,"lat":result.data.latitude},"offset":{"x":-9,"y":-31},"type":"Marker"}];

        function loadFeatures(){
            for(var feature, data, i = 0, len = features.length, j, jl, path; i < len; i++){
                data = features[i];
                switch(data.type){
                    case "Marker":
                        feature = new AMap.Marker({ map: map, position: new AMap.LngLat(data.lnglat.lng, data.lnglat.lat),
                            zIndex: 3, extData: data, offset: new AMap.Pixel(data.offset.x, data.offset.y), title: data.name,
                            content: '<div class="icon icon-' + data.icon + ' icon-'+ data.icon +'-' + data.color +'"></div>' });
                        break;
                    default: feature = null;
                }
            }
        }

        map = new AMap.Map("mapContainer", {center: new AMap.LngLat(center.lng, center.lat), level: level, keyboardEnable:true, dragEnable:true, scrollWheel:true, doubleClickZoom:true});

        loadFeatures();

        map.on('complete', function(){
            map.plugin(["AMap.ToolBar", "AMap.OverView", "AMap.Scale"], function(){
                map.addControl(new AMap.ToolBar({ruler: true, direction: true, locate: false})); map.addControl(new AMap.OverView({isOpen: true})); map.addControl(new AMap.Scale);
            });
        })

    }();








    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/company/editItem", function (data) {
            Feng.success("更新成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

});